//
//  UIView+Blank.m
//  OSChina
//
//  Created by 8b410-2 on 16/12/29.
//  Copyright © 2016年 abb. All rights reserved.
//

#import "UIView+Blank.h"
#import <objc/runtime.h>
@implementation UIView (Blank)
-(void)setLoginPageView:(OSCLogInPageView *)loginPageView{
    [self willChangeValueForKey:NSStringFromSelector(@selector(loginPageView))];
    objc_setAssociatedObject(self, @selector(loginPageView), loginPageView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    [self didChangeValueForKey:NSStringFromSelector(@selector(loginPageView))];
}
- (OSCLogInPageView *)loginPageView{
    return objc_getAssociatedObject(self, _cmd);
}
- (void)showLoginPageViewWithRect:(CGRect)rect {
    if (!self.loginPageView) {
        self.loginPageView = [[OSCLogInPageView alloc] initWithFrame:rect];
    }
    [self addSubview:self.loginPageView];
    [self bringSubviewToFront:self.loginPageView];
}
- (void)showLoginPageView{
    [self showLoginPageViewWithRect:self.bounds];
}
- (void)hideloginPageView{
    if (self.loginPageView) {
        [self.loginPageView removeFromSuperview];
        self.loginPageView = nil;
    }
}

@end
@interface OSCLogInPageView ()
@property (nonatomic,weak) UIImageView* loginImageView;
@property (nonatomic,weak) UILabel* loginTipLabel;
@property (nonatomic,weak) UIButton* loginButton;
@end

@implementation OSCLogInPageView
#pragma mark - init Method
- (instancetype)init{
    return [self initWithFrame:CGRectZero];
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        UIImageView* loginImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"ic_tip_fail"]];
        _loginImageView = loginImageView;
        [self addSubview:_loginImageView];
        
        UILabel* loginTipLabel = [[UILabel alloc]init];
        loginTipLabel.numberOfLines = 1;
        loginTipLabel.font = [UIFont systemFontOfSize:15];
        loginTipLabel.textAlignment = NSTextAlignmentCenter;
        loginTipLabel.textColor = [UIColor grayColor];
        loginTipLabel.text = @"亲,您还没登录呢~";
        _loginTipLabel = loginTipLabel;
        [self addSubview:_loginTipLabel];
        
        UIButton* loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
        loginButton.layer.masksToBounds = YES;
        loginButton.layer.cornerRadius = 15;
        loginButton.layer.borderColor = [UIColor grayColor].CGColor;
        loginButton.layer.borderWidth = 1.0f;
        [loginButton setBackgroundImage:[UIImage imageWithColor:[UIColor clearColor]] forState:UIControlStateNormal];
        [loginButton setBackgroundImage:[UIImage imageWithColor:[[UIColor grayColor] colorWithAlphaComponent:0.3]] forState:UIControlStateHighlighted];
        [loginButton setTitle:@"马上登录" forState:UIControlStateNormal];
        [loginButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [loginButton addTarget:self action:@selector(gotoLogIn) forControlEvents:UIControlEventTouchUpInside];
        _loginButton = loginButton;
        [self addSubview:_loginButton];
        
        
        [_loginImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@120);
            make.height.equalTo(@140);
            make.centerX.equalTo(self);
            make.bottom.equalTo(self.mas_centerY).offset(-80);
        }];
        
        [_loginTipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self);
            make.height.equalTo(@50);
            make.top.equalTo(_loginImageView.mas_bottom).offset(5);
        }];
        
        [_loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@120);
            make.height.equalTo(@40);
            make.centerX.equalTo(self);
            make.top.equalTo(_loginTipLabel.mas_bottom).offset(10);
        }];
    }
    return self;
}

#pragma mark --- Go to login
- (void)gotoLogIn{
    if (_didClickLogInBlock) {
        _didClickLogInBlock();
    }
}

@end

